package com.rychlickikicior.kitijdb;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class Descriptor {
    private Class classObject;
    private List<Query> queries = new ArrayList<Query>();
    private boolean version;
    private List<Child> children = new ArrayList<Child>();

    Class getClassObject() {
        return classObject;
    }

    void setClassObject(Class classObject) {
        this.classObject = classObject;
    }

    List<Query> getQueries() {
        return queries;
    }

    void setQueries(List<Query> queries) {
        this.queries = queries;
    }

    Query findQuery(String name, QueryType type) {
        for (Query q : this.queries)
            if (q.getName().equals(name) && type==q.getType())
                return q;
        return null;
    }

    void addChild(Class c, String v, Class colType) {
        this.children.add(new Child(c, v, colType));
    }

    String getChild(Class c) {
        Child child = new Child();
        child.setType(c);
        return this.children.get(this.children.indexOf(child)).getPropertyName();
    }

    Class getPropertyType(Class classType) {
        Child child = new Child();
        child.setType(classType);
        return this.children.get(this.children.indexOf(child)).getPropertyType();
    }

    

    Class getClassByValue(String value) {
        for (Child c : this.children) {
            if (c.getPropertyName().toLowerCase().equals(value.toLowerCase()))
                return c.getType();
        }
        return null;
    }

    Collection<Class> getChildClasses() {
        List<Class> list = new ArrayList<Class>();
        for (Child c : this.children)
            list.add(c.getType());
        return list;
    }

    Collection<String> getChildProperties() {
        List<String> list = new ArrayList<String>();
        for (Child c : this.children)
            list.add(c.getPropertyName());
        return list;
    }

    /**
     * @return the version
     */
    public boolean isVersion() {
        return version;
    }

    /**
     * @param version the version to set
     */
    public void setVersion(boolean version) {
        this.version = version;
    }
}
